<?php

class m131001_164314_create_tbls_menu_submenu extends CDbMigration
{
    public function up()
    {
        $this->createTable('tbl_menu',array(
            'id'=>'pk',
            'menu_name'     =>'string NOT NULL',
            'title'         =>'string NOT NULL',
            'description'   =>'string NOT NULL',
            'link_title'    =>'string NOT NULL',
            'module'        =>'string NOT NULL',
            'hidden'        =>'boolean DEFAULT 0',
            'position'      =>'int(4) NOT NULL',
            'type'          =>'int(1)',
            'create_time'    =>'datetime DEFAULT NULL',
            'update_time'   =>'datetime DEFAULT NULL',
        ), 'ENGINE=InnoDB');

        $this->createTable('tbl_submenu',array(
            'id'=>'pk',
            'submenu_name'   =>'string NOT NULL',
            'title'          =>'string NOT NULL',
            'parent_menu'    =>'int(11) NOT NULL',
            'hidden'         =>'boolean DEFAULT 0',
            'link_path'     =>'string NOT NULL',
            'link_title'    =>'string NOT NULL',
            'create_tme'    =>'datetime DEFAULT NULL',
            'update_time'   =>'datetime DEFAULT NULL',
        ), 'ENGINE=InnoDB');

        $this->addForeignKey('fk_menu_submenu','tbl_submenu','parent_menu','tbl_menu','id','CASCADE','RESTRICT');
    }

    public function down()
    {
        $this->dropTable('tbl_menu');
        $this->dropTable('tbl_submenu');
        $this->dropForeignKey('fk_menu_submenu','tbl_submenu');
    }

    /*
    // Use safeUp/safeDown to do migration with transaction
    public function safeUp()
    {
    }

    public function safeDown()
    {
    }
    */
}